home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2002 September / PCpro_2002_09.ISO / techtalk / automationsuite / 247setup.exe / {app} / Template / sql_update_stat.ini < prev    next >
Encoding:
INI File  |  2002-07-11  |  3.2 KB  |  100 lines

  1. ; Note: comment lines in .INI files always start with a semicolon
  2.  
  3. [Template]
  4. Description=Use this template to create a job automating "UPDATE STATISTICS" against all user-defined tables on all SQL Server databases.
  5.  
  6.  
  7. [Variables]
  8. ; Key values that have their name enclosed in % signs will be used for 
  9. ; template wizard questionnaire and substitution variables
  10. ; such key values should consist of 2 comma separated parts:
  11. ;    1. Field Edit Style (EDIT, YES/NO, FILE BROWSE, 
  12. ;                         DIR BROWSE, PROCESS BROWSE,
  13. ;                         FTP BROWSE, MAIL PROFILE LIST,
  14. ;                         REMOTE FILE BROWSE, REMOTE DIR BROWSE,
  15. ;                         REMOTE AGENT LIST, DB PROFILE LIST)
  16. ;    2. Prompt
  17. ;
  18. ; Example: %VAR%=EDIT,What is the name of the service that you want to monitor?
  19. ;
  20. ; Key values that don't have their name enclosed in % signs will be used for 
  21. ; job properties (See online help on "Job property names for use with JDL commands" 
  22. ; topic for more details).
  23. ;
  24. ; Example: DAY_NUMBER=1
  25.  
  26. %DB_PROFILE%=DB PROFILE LIST,Which SQL Server do you want to backup?
  27. %EMAIL_RECIPIENT%=EDIT,To whom do you want to sent the email alert in case if the backup fails:
  28. %EMAIL_PROFILE%=MAIL PROFILE LIST,If you use MAPI email interface, then which email profile do you want to use? If you use Lotus Notes or SMTP email interfaces, enter User ID required for logging to your email system.
  29. %EMAIL_PASSWORD%=EDIT,If you are required to login to your email system, what is your password:
  30. JOB_TYPE=D
  31. PROFILE=%DB_PROFILE%
  32. SCHEDULE_TYPE=D
  33. LOG=Y
  34. ASYNC=Y
  35. MONDAY=Y
  36. TUESDAY=Y
  37. WEDNESDAY=Y
  38. THURSDAY=Y
  39. WEDNESDAY=Y
  40. FRIDAY=Y
  41. SKIP_HOLIDAY=Y
  42. START_TIME=23:00
  43. SKIP=N
  44. MSG_ERROR=Y
  45. MSG_EMAIL=Y
  46. MSG_ACCOUNT=%EMAIL_PROFILE%
  47. MSG_PASSWORD=%EMAIL_PASSWORD%
  48. MSG_RECIPIENT=%EMAIL_RECIPIENT%
  49. DESCRIPTION=Every night this job runs UPDATE STATISTICS against all user-defined tables on all databases.
  50.  
  51. ; Notes: The script bellow can include substitution variables.
  52. ;        Substitution variables must be specified in %VAR% format 
  53. ;        where VAR is the variable name.
  54. ;
  55. ; Everything after the next line will be used for the template script.
  56. ;========================================================================================
  57. [Body]
  58.  
  59. DECLARE @tablename varchar(30)
  60. DECLARE @dbname varchar(30)
  61. DECLARE dbnames_cursor CURSOR FOR
  62. SELECT name 
  63. FROM sysdatabases
  64. WHERE name not in ('master','pubs','tempdb','model')
  65.  
  66. OPEN dbnames_cursor
  67. FETCH NEXT FROM dbnames_cursor INTO @dbname
  68.  
  69. WHILE (@@fetch_status <> -1)
  70. BEGIN
  71.     IF (@@fetch_status = -2)
  72.     BEGIN
  73.         FETCH NEXT FROM dbnames_cursor INTO @dbname
  74.         CONTINUE
  75.     END
  76.        
  77.     EXEC ('USE ' + @dbname + ' DECLARE tnames_cursor CURSOR FOR SELECT name from sysobjects where type = "U"')
  78.  
  79.     OPEN tnames_cursor
  80.     FETCH NEXT FROM tnames_cursor INTO @tablename
  81.  
  82.     WHILE (@@fetch_status <> -1)
  83.     BEGIN
  84.         IF (@@fetch_status = -2)
  85.         BEGIN
  86.             FETCH NEXT FROM tnames_cursor INTO @tablename
  87.             CONTINUE
  88.         END
  89.     
  90.         EXEC ('UPDATE STATISTICS ' + @dbname + '..' + @tablename )
  91.         EXEC ('USE ' + @dbname + ' EXEC sp_recompile ' + @tablename )
  92.         FETCH NEXT FROM tnames_cursor INTO @tablename
  93.       END
  94.  
  95.     DEALLOCATE tnames_cursor
  96.     FETCH NEXT FROM dbnames_cursor INTO @dbname
  97. END
  98.  
  99. DEALLOCATE dbnames_cursor
  100.